/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model;

import chatGUI.ChatGui;
import java.util.ArrayList;
import java.util.Observable;

/**
 *
 * @author Ridiss
 */
public class ChatModel extends Observable{
    
    private  ArrayList<String> userList ;
    private ChatGui gui;
    int d=0;
    
    /**
     * Permet au model de connaitre le gui.
     * @param gui
     */
    public ChatModel(ChatGui gui){
        this.userList = new ArrayList<String>(30);
        this.gui=gui;
        
    }
    
    /**
     *Cette methode permet de récupérer l'adresse ip de l'utilisateur.
     * 
     * @param usernam
     *             
     * @return
     */
    public String adrss(String usernam){
        String[] name = usernam.split("@");
     return name[1];
        
  }
     

    /**
     *Ajout de user
     * @param Username
     */
        public void addUser(String Username){
        for(String l:userList){
        if(adrss(Username).equals(adrss(l))){
        getUserList().remove(Username);
        }
        }
        userList.add(Username);
        System.out.println("On va ajouter: "+userList);
        gui.setListUser(userList);
      
    }
    
    

    /**
     * Suppression de user
     *
     * @param user
     */
        public void removeUser(String user){
        userList.remove(user);
        gui.setListUser(userList);
        System.out.println("On va supprimer: "+userList);
    }

    /**
     * @return the userList
     *              
     * 
     */
    public  ArrayList<String> getUserList() {
        return userList;
    }

    /**
     * @param userList the userList to set
     */
    public void setUserList(ArrayList<String> userList) {
        this.userList = userList;
    }
    
}
